package cn.xiaopengstack.domain.award.service.distribute.impl;

import cn.xiaopengstack.domain.award.aggregate.GiveOutCreditAwardAggregate;
import cn.xiaopengstack.domain.award.model.entity.AwardEntity;
import cn.xiaopengstack.domain.award.model.entity.DistributeMatterEntity;
import cn.xiaopengstack.domain.award.model.entity.UserCreditAwardEntity;
import cn.xiaopengstack.domain.award.repository.IRaffleAwardRepository;
import cn.xiaopengstack.domain.award.service.distribute.IDistributeAward;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @author jiangyangang
 * 黑名单1积分发奖实现
 */
@Component("user_credit_blacklist")
public class UserCreditBlackAward implements IDistributeAward {

    @Resource
    private IRaffleAwardRepository raffleAwardRepository;

    @Override
    public void distribute(DistributeMatterEntity distributeMatter) {

        AwardEntity awardEntity = distributeMatter.getAwardEntity();
        BigDecimal creditAmount = new BigDecimal(awardEntity.getAwardConfig());

        GiveOutCreditAwardAggregate giveOutCreditAwardAggregate = new GiveOutCreditAwardAggregate();
        giveOutCreditAwardAggregate.setUserId(distributeMatter.getUserId());
        giveOutCreditAwardAggregate.setUserAwardRecordEntity(distributeMatter.getUserAwardRecordEntity());
        giveOutCreditAwardAggregate.setUserCreditAwardEntity(UserCreditAwardEntity.builder()
                .creditAmount(creditAmount)
                .userId(distributeMatter.getUserId())
                .build());
        raffleAwardRepository.saveGiveOutCreditAwardOrder(giveOutCreditAwardAggregate);
    }
}
